﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Skyhook.AI.PathFinder
{
    internal class MovePath
    {
        Waypoint FirstWaypoint = null;
        Waypoint pCurrentWaypoint = null;
        Vector2 pTargetPoint;

        public MovePath()
        {
            Completed = false;
        }

        public void Clear()
        {
            FirstWaypoint = null;
            pCurrentWaypoint = null;
            Completed = false;
        }

        public void AddWaypointFirst(Waypoint waypoint)
        {
            if (FirstWaypoint == null)
            {
                pTargetPoint = new Vector2(waypoint.X + 0.5f, waypoint.Y + 0.5f);
            }
            waypoint.Next = FirstWaypoint;
            FirstWaypoint = waypoint;
        }

        public void StartPath()
        {
            pCurrentWaypoint = FirstWaypoint;
        }

        public bool Completed
        {
            get;
            private set;
        }

        public void StartPathFinding()
        {
            Completed = false;
        }

        public void PathFound()
        {
            Completed = true;
        }

        public Waypoint CurrentWaypoint
        {
            get
            {
                return pCurrentWaypoint;
            }
        }
        public void SetNextWaypoint()
        {
            if (pCurrentWaypoint != null)
            {
                if (pCurrentWaypoint.Next != null)
                {
                    pCurrentWaypoint = pCurrentWaypoint.Next;
                }
            }
        }
        public bool IsEmpty
        {
            get
            {
                return (pCurrentWaypoint == null);
            }
        }
        public bool IsLastPoint
        {
            get
            {
                return (pCurrentWaypoint.Next == null);
            }
        }
        public Vector2 TargetPoint
        {
            get
            {
                return pTargetPoint;
            }
        }
    }
}
